import { defineStore } from 'pinia'
import { userService_getUserInfo } from '@/apis/user'
import { ref } from 'vue'
// 存储user登录相关的pinia
export const useUserInfo = defineStore(
  'user',
  () => {
    const token = ref('')
    let userInfo = ref(null)

    const setToken = (myToken) => {
      token.value = myToken
    }

    const getToken = () => {
      return token.value
    }

    const getUserInfo = async () => {
      const { data } = await userService_getUserInfo()
      userInfo.value = data
    }

    return {
      token,
      setToken,
      getToken,
      getUserInfo,
      userInfo
    }
  },
  {
    persist: {
      key: 'custom-token',
      paths: ['token']
    }
  }
)
